package com.ql.service.keshi.impl;

import com.ql.dao.keshi.JianyanMapper;
import com.ql.pojo.keshi.JanYan;
import com.ql.service.keshi.JianyanService;
import com.ql.utils.PageHelper;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service("jianyanService")
public class JianyanServiceImpl implements JianyanService {

    private static final Logger LOGGER = Logger.getLogger(FangsheServiceImpl.class);
    @Resource
    private JianyanMapper jianyanMapper;
    @Override
    public boolean addNewJanYan(JanYan janYan) {
        int row = 0;
        try {
            row = jianyanMapper.save(janYan);
            if(row != 1){
                LOGGER.debug(" 保存放射科信息失败！");
                return false;
            }else{
                LOGGER.debug(" 保存放射科信息成功！");
                return true;
            }
        } catch (Exception e) {
            //e.printStackTrace();
            LOGGER.error("添加放射科信息异常》》》"+e.getMessage());
            return false;
        }
    }

    @Override
    public List<JanYan> getAllJanYan(PageHelper ph, String qryName) {
        List<JanYan> janYanList = new ArrayList<>();

        try {
            //add:更新总条数,
            //add 18.11.22:增加分页的条件
            ph.setTotalCount(jianyanMapper.qryCount(qryName));

            janYanList = jianyanMapper.qryAll((ph.getCurrentPageNo()-1)*ph.getPageSize(),ph.getPageSize(),qryName);
            if (janYanList.size() <= 0) {
                LOGGER.debug("查询为空！");
                //return userList;
            } else {
                LOGGER.debug(" 查询成功！");
            }
        } catch (Exception e) {
            LOGGER.error("异常：" + e.getMessage());
            //return userList;
        }
        return janYanList;
    }

    @Override
    public boolean removeJanYan(int jId) {
        int row = 0;
        /*  int fID = Integer.parseInt(fId);*/
        try {
            row = jianyanMapper.del(jId);
            if (row != 1) {
                LOGGER.debug(" 删除用户信息失败！");
                return false;
            } else {
                LOGGER.debug(" 删除用户信息成功！");
                return true;
            }
        } catch (Exception e) {
            LOGGER.error(" 删除用户信息异常》》》" + e.getMessage());
            return false;
        }
    }

    @Override
    public JanYan getJYKByuid(int uId) {
        JanYan jykByuid = null;
        try {
            jykByuid = jianyanMapper.qryJYKByuId(uId);
            if (jykByuid == null){
                LOGGER.debug("JianyanServiceImpl.getJYKByuid 查询为空！");
            }else {
                LOGGER.debug("JianyanServiceImpl.getJYKByuid 查询成功！");
            }
        } catch (Exception e) {
            LOGGER.error("JianyanServiceImpl.getJYKByuid 查询异常！"+e.getMessage());
        }
        return jykByuid;
    }
}
